//
//  JJFindViewController.m
//  DemoPro
//
//  Created by vpjacob on 2017/4/7.
//  Copyright © 2017年 vpjacob. All rights reserved.
//

#import "JJFindViewController.h"
#import "JJWangTest.h"
#import "JJWangModel.h"
#import "JJWangTestCell.h"
#import "JJDetailInformationController.h"
#import <UIImageView+WebCache.h>

@interface JJFindViewController ()

@property (nonatomic, strong)JJWangModel *wangModel;

@end

@implementation JJFindViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.title = @"发现";
    [self requestNetWork];
//    self.automaticallyAdjustsScrollViewInsets = NO;
    self.jjTableView.frame = CGRectMake(0, 0, JJ_SCREEN_WIDTH, JJ_SCREEN_HEIGHT - 110);
    
    [self.view addSubview:self.jjTableView];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return self.dataArray.count;
}



- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    JJWangTestCell *cell = [tableView dequeueReusableCellWithIdentifier:@"JJWangTestCell.xib"];
    if (cell == nil) {
        cell = [[[NSBundle mainBundle] loadNibNamed:@"JJWangTestCell" owner:self options:nil] firstObject];
    }
    JJWangModel *model = self.dataArray[indexPath.row];
    cell.address.text = model.address;
    cell.createTime.text = model.createTime;
    cell.title.text = model.title;
    cell.Ids.text = [NSString stringWithFormat:@"%zd",model.Ids];
    cell.age.text = cell.Ids.text = [NSString stringWithFormat:@"%zd",model.age];
    cell.phonenum.text = [NSString stringWithFormat:@"%zd",model.phonenum];
    NSURL* url = [NSURL URLWithString:model.memberHeading];
    [cell.iconImage sd_setImageWithURL:url placeholderImage:[UIImage imageNamed:@"guide1"]];
    return cell;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    return 200;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    JJDetailInformationController *vc = [JJDetailInformationController new];
    vc.model = self.dataArray[indexPath.row];
    [self.navigationController pushViewController:vc animated:YES];
}

- (void)requestNetWork{
    JJWangTest *api = [JJWangTest new];
    [api startWithCompletionBlockWithSuccess:^(__kindof YTKBaseRequest * _Nonnull request) {
        
        if ([request.responseObject[@"statusCode"] integerValue] == 1) {
            self.dataArray = [JJWangModel changeResponseJSONObject:request.responseObject[@"info"]];
            [self.jjTableView reloadData];
            NSLog(@"%@",self.dataArray);
        }
        
    } failure:^(__kindof YTKBaseRequest * _Nonnull request) {
        
    }];
}


@end
